export const BASE_URL = 'http://192.168.0.106:12521';
// export const BASE_URL = 'http://localhost:12521';

export function request(config = {}) {
	let {
		url,
		data = {}, //如果有回传数据，记录回传数据
		method = "GET", //默认都是get
		header = {} //请求头
	} = config

	url = BASE_URL + url
	console.log(url)
	//这里可以修改token
	// header['access-key'] = "770697"
	header['token'] = localStorage.getItem('token');
	// return 

	return new Promise((resolve, reject) => {
		uni.request({
			url,
			data,
			method,
			header,
			success: res => {
				if (res.data.code === 200) {
					resolve(res.data)
				} else if (res.data.code === 401 || res.data.code === 403) {
					uni.navigateTo({
						url: "/pages/login/login"
					});
					reject(res.data)
				} else if (res.data.code === 500) {
					uni.showModal({
						title: "错误提示",
						content: res.data.message,
						showCancel: false
					})
					reject(res.data)
				} else {
					uni.showToast({
						title: res.data.message,
						icon: "none"
					})
					reject(res.data)
				}
			},
			fail: err => {
				reject(err)
			}
		})
	})
}